package com.mh.dao;

import com.mh.domain.AppUserRole;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage AppUserRole entities.
 * 
 */
@Repository("AppUserRoleDAO")
@Transactional
public class AppUserRoleDAOImpl extends AbstractJpaDao<AppUserRole> implements
		AppUserRoleDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 * 
	 * @generated
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { AppUserRole.class }));
	/**
	 * EntityManager injected by Spring for persistence unit mhtest
	 *
	 * 
	 * @generated
	 */
	@PersistenceContext(unitName = "mhtest")
	private EntityManager entityManager;

	/**
	 * Instantiates a new AppUserRoleDAOImpl
	 *
	 * 
	 * @generated
	 */
	public AppUserRoleDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 * 
	 * @generated
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 * 
	 * @generated
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findAppUserRoleByUserName
	 *
	 */
	@Transactional
	public Set<AppUserRole> findAppUserRoleByUserName(String userName1) throws DataAccessException {

		return findAppUserRoleByUserName(userName1, -1, -1);
	}

	/**
	 * JPQL Query - findAppUserRoleByUserName
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AppUserRole> findAppUserRoleByUserName(String userName1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAppUserRoleByUserName", startResult, maxRows, userName1);
		return new LinkedHashSet<AppUserRole>(query.getResultList());
	}

	/**
	 * JPQL Query - findAppUserRoleById
	 *
	 */
	@Transactional
	public AppUserRole findAppUserRoleById(Integer id1) throws DataAccessException {

		return findAppUserRoleById(id1, -1, -1);
	}

	/**
	 * JPQL Query - findAppUserRoleById
	 *
	 */

	@Transactional
	public AppUserRole findAppUserRoleById(Integer id1, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findAppUserRoleById", startResult, maxRows, id1);
			return (com.mh.domain.AppUserRole) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findAllAppUserRoles
	 *
	 */
	@Transactional
	public Set<AppUserRole> findAllAppUserRoles() throws DataAccessException {

		return findAllAppUserRoles(-1, -1);
	}

	/**
	 * JPQL Query - findAllAppUserRoles
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AppUserRole> findAllAppUserRoles(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllAppUserRoles", startResult, maxRows);
		return new LinkedHashSet<AppUserRole>(query.getResultList());
	}

	/**
	 * JPQL Query - findAppUserRoleByRoleNameContaining
	 *
	 */
	@Transactional
	public Set<AppUserRole> findAppUserRoleByRoleNameContaining(String roleName1) throws DataAccessException {

		return findAppUserRoleByRoleNameContaining(roleName1, -1, -1);
	}

	/**
	 * JPQL Query - findAppUserRoleByRoleNameContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AppUserRole> findAppUserRoleByRoleNameContaining(String roleName1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAppUserRoleByRoleNameContaining", startResult, maxRows, roleName1);
		return new LinkedHashSet<AppUserRole>(query.getResultList());
	}

	/**
	 * JPQL Query - findAppUserRoleByPrimaryKey
	 *
	 */
	@Transactional
	public AppUserRole findAppUserRoleByPrimaryKey(Integer id1) throws DataAccessException {

		return findAppUserRoleByPrimaryKey(id1, -1, -1);
	}

	/**
	 * JPQL Query - findAppUserRoleByPrimaryKey
	 *
	 */

	@Transactional
	public AppUserRole findAppUserRoleByPrimaryKey(Integer id1, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findAppUserRoleByPrimaryKey", startResult, maxRows, id1);
			return (com.mh.domain.AppUserRole) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findAppUserRoleByApplication
	 *
	 */
	@Transactional
	public Set<AppUserRole> findAppUserRoleByApplication(String application1) throws DataAccessException {

		return findAppUserRoleByApplication(application1, -1, -1);
	}

	/**
	 * JPQL Query - findAppUserRoleByApplication
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AppUserRole> findAppUserRoleByApplication(String application1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAppUserRoleByApplication", startResult, maxRows, application1);
		return new LinkedHashSet<AppUserRole>(query.getResultList());
	}

	/**
	 * JPQL Query - findAppUserRoleByUserNameContaining
	 *
	 */
	@Transactional
	public Set<AppUserRole> findAppUserRoleByUserNameContaining(String userName1) throws DataAccessException {

		return findAppUserRoleByUserNameContaining(userName1, -1, -1);
	}

	/**
	 * JPQL Query - findAppUserRoleByUserNameContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AppUserRole> findAppUserRoleByUserNameContaining(String userName1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAppUserRoleByUserNameContaining", startResult, maxRows, userName1);
		return new LinkedHashSet<AppUserRole>(query.getResultList());
	}

	/**
	 * JPQL Query - findAppUserRoleByRoleName
	 *
	 */
	@Transactional
	public Set<AppUserRole> findAppUserRoleByRoleName(String roleName1) throws DataAccessException {

		return findAppUserRoleByRoleName(roleName1, -1, -1);
	}

	/**
	 * JPQL Query - findAppUserRoleByRoleName
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AppUserRole> findAppUserRoleByRoleName(String roleName1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAppUserRoleByRoleName", startResult, maxRows, roleName1);
		return new LinkedHashSet<AppUserRole>(query.getResultList());
	}

	/**
	 * JPQL Query - findAppUserRoleByApplicationContaining
	 *
	 */
	@Transactional
	public Set<AppUserRole> findAppUserRoleByApplicationContaining(String application1) throws DataAccessException {

		return findAppUserRoleByApplicationContaining(application1, -1, -1);
	}

	/**
	 * JPQL Query - findAppUserRoleByApplicationContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AppUserRole> findAppUserRoleByApplicationContaining(String application1, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAppUserRoleByApplicationContaining", startResult, maxRows, application1);
		return new LinkedHashSet<AppUserRole>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(AppUserRole entity) {
		return true;
	}
}
